class Solution {
public:
    int maxSubArray(vector<int>& nums)
    {
        int ans = nums[0], prev = 0, min_prev = 0;
        for(auto& e : nums)
        {
            prev = prev + e;
            ans = max(ans, prev - min_prev);
            min_prev = min(min_prev, prev);
        }    
        return ans;
    }
};